//
//  UIDatePickerSnapEx.swift
//  NetProject
//
//  Created by EDY on 2021/11/3.
//

import Foundation

//import DatePickerView
// MARK: ===================================工厂类:DatePickerView SnapKit=========================================
public extension DatePickerView {
    
    /// 初始化DatePickerView
    /// - Parameters:
    ///   - type: DatePickerStyle样式
    ///   - selectDate: 已选定时间
    ///   - minYear:  滚轮最小年份(不需要选择年费可不加)
    ///   - maxYear: 滚轮最大年份(不需要选择年费可不加)
    ///   - showUnit: 是否显示单位(年月日等)
    ///   - callBack: 回调Date
    @discardableResult
    class func snpDatePickerView(supView: UIView? = nil,
                                 type: DatePickerStyle,
                                 selectDate: Date = Date(),
                                 minYear: Int = Date().getYear(),
                                 maxYear: Int = Date().getYear() + 5,
                                 showUnit: Bool = true,
                                 snapKitMaker: ((ConstraintMaker) -> Void)? = nil,
                                 callBack: @escaping PickerClosure) -> DatePickerView {
        
        let view = DatePickerView.init(type: type, selectDate: selectDate, minYear: minYear, maxYear: maxYear, showUnit: showUnit, callBack: callBack)
        
        guard let sv = supView, let maker = snapKitMaker else {
            return view
        }
        sv.addSubview(view)
        view.snp.makeConstraints { (make) in
            maker(make)
        }
        
        return view
    }
    
}
